import { registerAs } from '@nestjs/config';

export const appConfig = registerAs('app', () => ({
  nodeEnv: process.env.NODE_ENV || 'development',
  port: parseInt(process.env.PORT, 10) || 3001,
  apiPrefix: process.env.API_PREFIX || 'api/v1',

  // CORS配置
  cors: {
    origin: process.env.CORS_ORIGIN || 'http://localhost:3000',
    credentials: process.env.CORS_CREDENTIALS === 'true',
  },

  // WebSocket配置
  websocket: {
    cors: {
      origin: process.env.WS_CORS_ORIGIN || 'http://localhost:3000',
      credentials: process.env.WS_CORS_CREDENTIALS === 'true',
    },
  },

  // JWT配置
  jwt: {
    secret: process.env.JWT_SECRET || 'your-super-secret-jwt-key',
    expiresIn: process.env.JWT_EXPIRES_IN || '24h',
  },

  // 房间配置
  room: {
    expiryMinutes: parseInt(process.env.ROOM_EXPIRY_MINUTES, 10) || 5,
    maxParticipants: parseInt(process.env.MAX_PARTICIPANTS_PER_ROOM, 10) || 2,
    maxRoomsPerIp: parseInt(process.env.MAX_ROOMS_PER_IP, 10) || 5,
  },

  // 限流配置
  throttle: {
    ttl: parseInt(process.env.THROTTLE_TTL, 10) || 60,
    limit: parseInt(process.env.THROTTLE_LIMIT, 10) || 100,
  },

  // 安全配置
  security: {
    helmetEnabled: process.env.HELMET_ENABLED === 'true',
    compressionEnabled: process.env.COMPRESSION_ENABLED === 'true',
  },

  // 健康检查配置
  health: {
    enabled: process.env.HEALTH_CHECK_ENABLED !== 'false',
    path: process.env.HEALTH_CHECK_PATH || '/health',
  },

  // 监控配置
  metrics: {
    enabled: process.env.METRICS_ENABLED === 'true',
    path: process.env.METRICS_PATH || '/metrics',
  },

  // 日志配置
  logging: {
    level: process.env.LOG_LEVEL || 'debug',
    fileEnabled: process.env.LOG_FILE_ENABLED === 'true',
    filePath: process.env.LOG_FILE_PATH || 'logs',
  },
}));
